package com.edfu.core.identitymgt.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.edfu.core.identitymgt.service.api.IIdentityMgtService;
import com.edfu.core.identitymgt.service.api.EDUUserDetailsService;
import com.edfu.core.identitymgt.vo.UserEnrollment;


public class EDUUserDetailsServiceImpl implements EDUUserDetailsService {
	
	@Autowired
	private IIdentityMgtService identityMgtService;

	@Override
	public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException, DataAccessException {
		com.edfu.core.identitymgt.vo.User user = identityMgtService.getUser(userName);
		
		if (user != null) {
			UserEnrollment userEnrollment = new UserEnrollment();
			userEnrollment.setUser(user);
			// get and set user role //TODO
//			return userEnrollment;
			return null;
		} else {
			throw new UsernameNotFoundException("No User with username : " + userName);
		}		
		
	}	

}
